<template>
  <div>
    <!-- 区域大订单退款审核-->
    <TopFilter ref="topform" :list="topFilterList" :cols="3" @filterChange="changeHandle" @onCollapse="collapseHandle" :labelWidth="110" @resetChange="resetChange" />
    <Spin :spinning="exportLoading" tip="Loading...">
      <FilterTables
        ref="table"
        :columns="columns"
        :fetchapi="fetchApi"
        :params="fetchParams"
        :maxHeight="800"
        :datakey="'records'"
        columnsRef="KeyCustomerInfo"
        :isSelectColumn="false"
        :onColumnsChange="(columns) => (this.columns = columns)"
      >
        <!-- <template slot="controls" slot-scope="props">
          <multiuse-button size="small" type="primary" @click="addHandle">新 增</multiuse-button>
        </template> -->
      </FilterTables>
    </Spin>
    <Drawer :visible.sync="detailVisible" :title="'区域大定退款审核'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }" width="72%">
      <shenhe :type="deailType" :rowData="formData" @close="infoClose"/>
    </Drawer>
    <Drawer :visible.sync="isreject" :title="'大定退款申请明细'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <detailModel :rowData="selectedList" @close="rejectclose" />
    </Drawer>
    <BaseDialog :visible.sync="issearch" :title="'经销商查询'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <ownerSeacher :type="type" @close="ownercloseHandler" @save="delearSave" selectionType="multiple" />
    </BaseDialog>
  </div>
</template>
<script>
// D:\gongzuo\pkcms\vue\cms\src\api\omSaleP\BigOrderRefund\AreaBigOrderRefundAudit\index.js
import { getList } from '@/api/omSaleP/BigOrderRefund/AreaBigOrderRefundAudit/index.js';
import { exportExcelFile } from '@/utils';
import ownerSeacher from './ownerSeacher';
import detailModel from './detailModel';
import { dictionary } from '@/utils/dictMixin';
import examine from "./examine";
import { getAppId } from '@/assets/js/auth';
import Shenhe from "./shenhe"; //获取登录用户
export default {
  name: 'KeyCustomerInfo',
  data() {
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchParams: {
        applyType: 21581002
      },
      fetchApi: getList,
      formData: {},
      deailType: '',
      exportLoading: false,
      issearch: false,
      detailVisible: false,


      iswarehouse: false,
      isEmit: false,

      fromDealer: '',
      toDealer: '',
      dealerData: [],
      selectDealerData: [],
      type: 0,
      isOpen: true,
      selectedList: [],
      isreject: false
    };
  },
  components: {
    Shenhe,
    detailModel,
    ownerSeacher,
  },
  mixins: [dictionary],
  mounted() {},
  created() {},
  methods: {
    // changeHandle(params) {
    //   this.fetchParams = { ...this.fetchParams, ...params };
    // },
    // 新增
    // addHandle() {
    //   this.deailType = 'add';
    //   this.formData = {};
    //   this.detailVisible = true;
    // },
    // 数据操作
    async editHandle(row, type) {
      if (type != 'delete') {
        //编辑、明细
        this.deailType = type;
        this.detailVisible = true;
        this.formData = row;
      } else {
        //删除
        await this.$confirm('是否确定删除?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
          .then(async () => {
            const res = await deleteBigCustomer({ id: row.id });
            if (res.resultCode === 200) {
              this.$notify.success({ title: '提示信息', message: '删除成功' });
            }
            this.fetchParams = Object.assign({}, this.fetchParams);
          })
          .catch(() => {});
      }
    },
    infoClose(rData) {
      this.detailVisible = false;
      // if (rData.type === 'refresh') {
        // 重新加载
      this.fetchParams = Object.assign({}, this.fetchParams);
      // }
    },
    // detailcloseHandler() {
    //   this.detailVisible = false;
    //   // if (this.deailType !== 'detail') {
    //   this.fetchParams = Object.assign({}, this.fetchParams);
    //   // }
    // },
    createdFrom() {
      return [
        {
          type: 'INPUT',
          label: '客户名称',
          placeholder: '请输入',
          fieldName: 'customerName',//CUSTOMER_NAME
        },
        {
          type: 'INPUT',
          label: '手机号',
          placeholder: '请输入',
          fieldName: 'customerMobile', //CUSTOMER_MOBILE
        },
        {
          type: 'INPUT',
          label: '大定预订单号',
          placeholder: '请输入',
          fieldName: 'wishApplyNo',//WISH_APPLY_NO
        },

        {
          type: 'SELECT',
          label: '申请状态',
          fieldName: 'applyType',//APPLY_TYPE
          placeholder: '请选择',
          itemList: this.createDictList('2158').filter((item) => item.value == '21581002' || item.value == '21581003' || item.value == '21581004' || item.value == '21581005' || item.value == '21581006'),
          initialValue: 21581002,
        },

        {
          type: 'INPUT',
          label: '申请经销商',
          fieldName: 'dealerName',
          placeholder: '请选择',
          // readonly: true,
          render: (p) => {
            return (
              <div>
                <el-select v-model={this.selectDealerData} disabled={true} multiple collapse-tags placeholder="请选择">
                  {this.dealerData.map((item) => (
                    <el-option key={item.dealerCode} label={item.dealerShortname} value={item.dealerCompanyCode} />
                  ))}
                </el-select>
                <multiuse-button style="position: absolute;right: 0;height:100%" icon="el-icon-search" onClick={() => this.issearch = true} />
              </div>
            );
          },
        },

        {
          type: 'RANGE_DATE',
          label: '申请日期',
          fieldName: 'beginOutDate|endOutDate',//APPLY_REFUND_TIME
          initialValue: '',
          format: 'yyyy-MM-dd',
          dateType: 'exactdaterange',
        },

      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: (props) => {
            return <span>{props.row.index + 1}</span>;
          },
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 150,
          algin: 'center',
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <multiuse-button size="mini" type="text" disabled={props.row.applyType !=21581002 } onClick={() => this.editHandle(props.row, 'edit')}>
                  审核
                </multiuse-button>
                {/* <multiuse-button size="mini" type="text" disabled={props.row.status != 21461001} onClick={() => this.editHandle(props.row, 'delete')}>
                  删除
                </multiuse-button> */}
                {/*<multiuse-button size="mini" type="text" onClick={() => this.editHandle(props.row, 'detail')}>
                  查看
                </multiuse-button>*/}
                <multiuse-button size="mini" type="text" onClick={() => this.detailHandle(props.row, 'show')}>
                  查看
                </multiuse-button>
              </div>
            );
          },
        },
        {
          title: '申请状态',
          dataIndex: 'applyType',//REA_AUDIT_TYPE
          sorter: true,
          // filter: true,
          // filterType: 'input',

          render: (p) => {
            return <span>{this.createDictText(p.row.applyType, '2158')}</span>;
          },
        },

        {
          title: '申请单号',
          dataIndex: 'applyNo',//APPLY_NO
          sorter: true,
          // filter: true,
          // filterType: 'input',
          // render: (p) => {
          //   return <span>{this.createDictText(p.row.status, '2146')}</span>;
          // },
        },
        {
          title: '大定预订单号',
          dataIndex: 'wishApplyNo',//WISH_APPLY_NO
          sorter: true,
          // filter: true,
          // filterType: 'input',
          width: 200,
        },
        {
          title: '客户名称',
          dataIndex: 'customerName',//CUSTOMER_NAME
          sorter: true,
          // filter: true,
          // filterType: 'input',
          width: 200,
        },
        {
          title: '手机号',
          dataIndex: 'customerMobile',//CUSTOMER_MOBILE
          sorter: true,
          // filter: true,
          // filterType: 'input',
        },
        {
          title: '大定金额',
          dataIndex: 'largeFixedAmount',//LARGE_FIXED_AMOUNT
          sorter: true,
          // filter: true,
          // filterType: 'input',
        },
        // {
        //   title: '下单时间',
        //   dataIndex: 'ordersTime',//ORDERS_TIME
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input',
        //   dateFormat: 'yyyy-MM-dd',
        // },

        {
          title: '支付时间',
          dataIndex: 'paymentTime',//PAYMENT_TIME
          sorter: true,
          // filter: true,
          // filterType: 'date-range'

        },
        {
          title: '申请退款时间',
          dataIndex: 'applyRefundTime',//APPLY_REFUND_TIME
          sorter: true,
          // filter: true,
          // filterType: 'date-range'
        },
        {
          title: '区域审核时间',
          dataIndex: 'areaRauditTime',//AREA_RAUDIT_TIME
          sorter: true,
          // filter: true,
          // filterType: 'date-range'
        },
        {
          title: '车厂审核时间',
          dataIndex: 'factoryRauditTime',  //FACTORY_RAUDIT_TIME
          sorter: true,
          // filter: true,
          // filterType: 'date-range'
        },
        {
          title: '申请经销商',
          dataIndex: 'dealerName',//DEALER_NAME
          sorter: true,
          // filter: true,
          // filterType: 'input',

        },
        {
          title: '所属区域',
          dataIndex: 'regional',//REGIONAL
          sorter: true,
          // filter: true,
          // filterType: 'input',

        },
        {
          title: '申请人',
          dataIndex: 'applyPersonName',//APPLY_PERSON_NAME
          sorter: true,
          // filter: true,
          // filterType: 'input',

        },
        {
          title: '申请理由',
          dataIndex: 'applyReason',//APPLY_REASON
          sorter: true,
          // filter: true,
          // filterType: 'input',

        },
        {
          title: '区域审核人',
          dataIndex: 'areaAuditBy',//AREA_AUDIT_BY
          sorter: true,
          // filter: true,
          // filterType: 'input',

        },

        {
          title: '区域审核意见',
          dataIndex: 'areaAuditOpinion', //AREA_AUDIT_OPINION
          sorter: true,
          // filter: true,
          // filterType: 'input',

        },
        {
          title: '车厂审核人',
          dataIndex: 'factoryAuditBy',//FACTORY_AUDIT_BY
          sorter: true,
          // filter: true,
          // filterType: 'input',

        },
        {
          title: '车厂审核意见',
          dataIndex: 'factoryAuditOpinion',//FACTORY_AUDIT_OPINION
          sorter: true,
          // filter: true,
          // filterType: 'input',

        },


      ];
    },
    seacherFun(type) {
      this.type = type;
      this.issearch = true;
    },
    selectChangeHandle(row) {
      if (row.length > 0) {
        let isOpen = true;
        row.map(x => {
          if (x.applyStatus != 60121002) {
            isOpen = false;
          }
        });
        this.isOpen = isOpen ? false : true;
        this.selectedList = row;
      } else {
        this.selectedList = [];
        this.isOpen = true;
        if (getAppId() == 'beijing') {
          this.isOpen = false;
        }
      }
    },
    //搜索获取数据
    changeHandle(params) {


      params.dealerNameStr = this.selectDealerData
      this.fetchParams = Object.assign({}, this.fetchParams, params);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    delearSave(obj) {
      console.log('选择数据传递', obj);
      this.dealerData = obj;
      this.selectDealerData = [];
      obj.forEach(item => {
        this.selectDealerData.push(item.dealerName);
      });
      console.log('this.selectDealerData=====', this.selectDealerData);
      this.issearch = false;
    },

    ownercloseHandler(val, type) {

      this.issearch = false;
    },
    editHandle2(data, type) {
      this.formData = data;
      this.isEmit = true;
    },
    detailHandle(data, type){
      this.selectedList = data;
      this.isreject = true;
    },
    emitcloseHandler(val) {
      this.isEmit = false;
      // this.fetchParams.fromDealer = this.fromDealer;
      // this.fetchParams.toDealer = this.toDealer;
      this.fetchParams = Object.assign({}, this.fetchParams);

    },
    rejectclose(val) {
      this.isreject = false;
      this.fetchParams = Object.assign({}, this.fetchParams);
    },
    resetChange() {
      this.selectDealerData= []
      this.fetchParams = Object.assign({}, this.fetchParams,{dealerNameStr:this.selectDealerData});
    }

  },
};
</script>
